package com.art.sunflower.mapper;

import com.art.sunflower.pojo.Classes;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface ClassesMapper {

    @Insert("insert into classes(classes_name,course_id,teacher_id,startweek, endweek,truefee,maxNum) values(#{classesName},#{courseId}, #{teacherId}," +
            "#{startweek},#{endweek},#{truefee},#{maxNum})")
    int insertClasses(String classesName, int courseId, int teacherId, String startweek, String endweek, int truefee, int maxNum);

    @Update("update classes set classes_name=#{classesName},course_id=#{courseId},teacher_id=#{teacherId},startweek=#{startweek},endweek=#{endweek}," +
            "truefee=#{truefee},maxNum=#{maxNum} where id = #{id}")
    int updateClasses(int id, String classesName, int courseId, int teacherId, String startweek, String endweek, int truefee, int maxNum);

    @Delete("delete from classes where id = #{id}")
    int deleteClasses(int id);

    @Select("select * from classes_select_view where id=#{id}")
    Map<String, Object> selectOneClasses(int id);

    @Select("select * from classes_select2_view where id=#{id}")
    Map<String, Object> selectOneClasses2(int id);

    @Select("select * from classes_select_view")
    List<Map<String, Object>> listAllClasses();

    @Select("select * from classes_select2_view")
    List<Map<String, Object>> listAllClasses2();


    @Insert("insert into classes(classes_name,course_id,teacher_id,startweek,endweek,truefee,maxNum) values(#{classesName},#{courseId}, #{teacherId}, #{startweek}," +
            "#{endweek},#{truefee},#{maxNum})")
    int addOpenClasses(String classesName, int courseId, int teacherId, String startweek, String endweek, int truefee, int maxNum);

    @Delete("delete from classes where id = #{id}")
    int deleteOpenClasses(int id);

    @Update("update classes set classes_name=#{classesName},course_id=#{courseId},teacher_id=#{teacherId}, startweek=#{startweek}, " +
            "endweek=#{endweek},truefee=#{truefee},maxNum=#{maxNum} where id = #{id}")
    int updateOpenClasses(int id, String classesName, int courseId, int teacherId, String startweek, String endweek, int truefee, int maxNum);

    @Select("select * from classes_select_view")
    List<Map<String, Object>> listAllOpenClasses();

    @Select("select * from classes_select_view")
    List<Map<String, Object>> listAllOpenClasses2();

    @Select("select * from classes_select_view")
    Map<String, Object> selectOneOpenClasses(int id);

    @Select("select * from classes_select_view")
    Map<String, Object> selectOneOpenClasses2(int id);

    @Select("select c.id, c.classes_name, co.course_name,c.startweek,c.endweek,u.username,c.truefee,c.maxNum,c.status " +
            "from classes as c,user as u,course as co WHERE c.course_id = co.id AND c.teacher_id = u.id AND teacher_id = #{teacherId}")
    List<Map<String, Object>> findClassesByTeacher(int teacherId, Integer pagenum, Integer pagesize);

    @Update("update classes set trueNum=#{trueNum},maxNum=#{maxNum},status=#{status} where id=#{id}")
    int openClasses(int id, int trueNum, int maxNum, boolean status);

    @Select("select * from classes where id = #{id}")
    Classes selectClasses(int id);

    @Insert("insert into classes_order(student_id, classes_id, truefee, time values(#{studentId}, #{classesId}, #{fee}, #{time})")
    void insertClassesOrder(Integer studentId, Integer classesId, Integer fee, String time);

    @Update("update classes set trueNum = #{trueNum} where id = #{id}")
    void updateTrueNum(Integer id, Integer trueNum);

    @Select("select grade, requirement enroll_grade_view where id = #{id}")
    Map<String, Object> selectEnroll(Integer id);

    @Select("select * from classes_information_view where id = #{id}")
    Map<String, Object> selectClassesInfor(Integer id);

}

